//
//  WaybillListCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/10/26.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "WaybillListCell.h"

@interface WaybillListCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UIButton *fuZhiBtn;
@property (nonatomic, strong) UIButton *operationBtn;
@property (nonatomic, strong) UIView *addressBgView;
@property (nonatomic, strong) UILabel *fromAddLab;
@property (nonatomic, strong) UIImageView *statusImgView;
@property (nonatomic, strong) UILabel *statusLab;
@property (nonatomic, strong) UILabel *toAddLab;
@property (nonatomic, strong) UILabel *shouTitleLab;
@property (nonatomic, strong) UILabel *shouLab;
@property (nonatomic, strong) UILabel *yunTitleLab;
@property (nonatomic, strong) UILabel *yunLab;
@property (nonatomic, strong) UILabel *pieceTitleLab;
@property (nonatomic, strong) UILabel *pieceLab;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *faTimeTitleLab;
@property (nonatomic, strong) UILabel *faTimeLab;
@property (nonatomic, strong) UILabel *daoTimeTitleLab;
@property (nonatomic, strong) UILabel *daoTimeLab;

@end

@implementation WaybillListCell

+ (instancetype)WaybillListCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"WaybillListCell";
    WaybillListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[WaybillListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        self.noTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.textColor = HexColor(0x2B2C44);
        self.noLab.font = BoldFontOfSize(12);
        [self.bgView addSubview:self.noLab];
        
        self.fuZhiBtn = [UIButton new];
        [self.bgView addSubview:self.fuZhiBtn];
        
        self.operationBtn = [UIButton new];
        self.operationBtn.layer.masksToBounds = YES;
        self.operationBtn.layer.cornerRadius = 15;
        [self.operationBtn setBackgroundColor:Color_ThemeColor];
        [self.operationBtn setTitle:@"受理" forState:0];
        [self.operationBtn setTitleColor:HexColor(0xffffff) forState:0];
        self.operationBtn.titleLabel.font = BoldFontOfSize(14);
        [self.operationBtn addTarget:self action:@selector(operationClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.operationBtn];
        
        self.addressBgView = [UIView new];
        self.addressBgView.backgroundColor = HexColor(0xF7F7FA);
        self.addressBgView.layer.masksToBounds = YES;
        self.addressBgView.layer.cornerRadius = 2;
        [self.bgView addSubview:self.addressBgView];
        
        self.fromAddLab = [UILabel new];
        self.fromAddLab.textColor = HexColor(0x2B2C44);
        self.fromAddLab.font = BoldFontOfSize(20);
        self.fromAddLab.textAlignment = NSTextAlignmentCenter;
        [self.addressBgView addSubview:self.fromAddLab];
        
        self.statusImgView = [UIImageView new];
        [self.addressBgView addSubview:self.statusImgView];
        
        self.statusLab = [UILabel new];
        self.statusLab.textColor = HexColor(0x2B2C44);
        self.statusLab.font = BoldFontOfSize(12);
        [self.addressBgView addSubview:self.statusLab];
        
        self.toAddLab = [UILabel new];
        self.toAddLab.textColor = HexColor(0x2B2C44);
        self.toAddLab.font = BoldFontOfSize(20);
        self.toAddLab.textAlignment = NSTextAlignmentCenter;
        [self.addressBgView addSubview:self.toAddLab];
        
        self.shouTitleLab = [UILabel new];
        self.shouTitleLab.textColor = HexColor(0x9C9DB3);
        self.shouTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.shouTitleLab];
        
        self.shouLab = [UILabel new];
        self.shouLab.textColor = HexColor(0x2B2C44);
        self.shouLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.shouLab];
        
        self.yunTitleLab = [UILabel new];
        self.yunTitleLab.textColor = HexColor(0x9C9DB3);
        self.yunTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.yunTitleLab];
        
        self.yunLab = [UILabel new];
        self.yunLab.textColor = HexColor(0x2B2C44);
        self.yunLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.yunLab];
        
        self.pieceTitleLab = [UILabel new];
        self.pieceTitleLab.textColor = HexColor(0x9C9DB3);
        self.pieceTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.pieceTitleLab];
        
        self.pieceLab = [UILabel new];
        self.pieceLab.textColor = HexColor(0x2B2C44);
        self.pieceLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.pieceLab];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = HexColor(0x9C9DB3);
        self.countTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [UILabel new];
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.countLab];
        
        self.faTimeTitleLab = [UILabel new];
        self.faTimeTitleLab.textColor = HexColor(0x9C9DB3);
        self.faTimeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.faTimeTitleLab];
        
        self.faTimeLab = [UILabel new];
        self.faTimeLab.textColor = HexColor(0x2B2C44);
        self.faTimeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.faTimeLab];
        
        self.daoTimeTitleLab = [UILabel new];
        self.daoTimeTitleLab.textColor = HexColor(0x9C9DB3);
        self.daoTimeTitleLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.daoTimeTitleLab];
        
        self.daoTimeLab = [UILabel new];
        self.daoTimeLab.textColor = HexColor(0x2B2C44);
        self.daoTimeLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.daoTimeLab];
    }
    return self;
}

- (void)operationClick {
    if (self.shouLiBlock) {
        self.shouLiBlock();
    }
}

-(void)setModel:(WaybillMainModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.noTitleLab.text = @"运单号：";
    self.noTitleLab.nim_left = 10;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.wa_num;
    self.noLab.nim_left = self.noTitleLab.nim_right;
    [self.noLab sizeToFit];
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.fuZhiBtn.nim_left = self.noLab.nim_right + 6;
    self.fuZhiBtn.nim_width = 18;
    self.fuZhiBtn.nim_height = 18;
    self.fuZhiBtn.nim_centerY = self.noLab.nim_centerY;
    [self.fuZhiBtn setImage:[UIImage imageNamed:@"icon_ladingbill_erweima"] forState:0];
    
    self.operationBtn.nim_width = 60;
    self.operationBtn.nim_height = 30;
    self.operationBtn.nim_left = self.bgView.nim_width - 10 - self.operationBtn.nim_width;
    self.operationBtn.nim_centerY = self.noTitleLab.nim_centerY;
    if ([self.model.status isEqualToString:@"1"]) {
        [self.operationBtn setTitle:@"受理" forState:0];
    }else {
        self.operationBtn.frame = CGRectZero;
    }
    
    self.addressBgView.frame = CGRectMake(self.noTitleLab.nim_left, self.noTitleLab.nim_bottom + 10, self.bgView.nim_width - 2 * self.noTitleLab.nim_left, 69);
    
    self.statusImgView.nim_width = 59;
    self.statusImgView.nim_height = 10;
    self.statusImgView.nim_left = (self.addressBgView.nim_width - self.statusImgView.nim_width) * 0.5;
    self.statusImgView.nim_top = 27;
    if ([self.model.status isEqualToString:@"1"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_shouli"]];
    }else if ([self.model.status isEqualToString:@"2"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_fenpei"]];
    }else if ([self.model.status isEqualToString:@"3"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_bohui"]];
    }else if ([self.model.status isEqualToString:@"5"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_tuzhong"]];
    }else if ([self.model.status isEqualToString:@"12"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_huidanqueren"]];
    }else if ([self.model.status isEqualToString:@"15"]) {
        [self.statusImgView setImage:[UIImage imageNamed:@"waybill_wancheng"]];
    }else {
        [self.statusImgView setImage:[UIImage imageNamed:@""]];
    }
    
    self.statusLab.text = self.model.status_name;
    [self.statusLab sizeToFit];
    self.statusLab.nim_centerX = self.statusImgView.nim_centerX;
    self.statusLab.nim_top = self.statusImgView.nim_bottom + 5;
    
    self.fromAddLab.nim_left = 10;
    self.fromAddLab.text = self.model.start_city;
    [self.fromAddLab sizeToFit];
    self.fromAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.fromAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.toAddLab.nim_left = 10 + self.statusImgView.nim_right;
    self.toAddLab.text = self.model.end_city;
    [self.toAddLab sizeToFit];
    self.toAddLab.nim_width = self.statusImgView.nim_left - 20;
    self.toAddLab.nim_centerY = self.statusImgView.nim_centerY;
    
    self.shouTitleLab.text = @"收货单位：";
    [self.shouTitleLab sizeToFit];
    self.shouTitleLab.nim_left = 10;
    self.shouTitleLab.nim_top = self.addressBgView.nim_bottom + 10;
    
    self.shouLab.text = self.model.shipper_name;
    [self.shouLab sizeToFit];
    self.shouLab.nim_left = self.shouTitleLab.nim_right;
    self.shouLab.nim_centerY = self.shouTitleLab.nim_centerY;
    self.shouLab.nim_width = self.bgView.nim_width - 10 - self.shouTitleLab.nim_right;
    
    self.yunTitleLab.text = @"承运单位：";
    [self.yunTitleLab sizeToFit];
    self.yunTitleLab.nim_left = 10;
    self.yunTitleLab.nim_top = self.shouTitleLab.nim_bottom + 5;
    
    self.yunLab.text = self.model.tlogistics_name;
    [self.yunLab sizeToFit];
    self.yunLab.nim_left = self.yunTitleLab.nim_right;
    self.yunLab.nim_centerY = self.yunTitleLab.nim_centerY;
    self.yunLab.nim_width = self.bgView.nim_width - 10 - self.yunTitleLab.nim_right;
    
    self.pieceTitleLab.text = @"货物件数：";
    [self.pieceTitleLab sizeToFit];
    self.pieceTitleLab.nim_left = 10;
    self.pieceTitleLab.nim_top = self.yunTitleLab.nim_bottom + 5;
    
    self.pieceLab.text = self.model.goods_jnum;
    [self.pieceLab sizeToFit];
    self.pieceLab.nim_left = self.pieceTitleLab.nim_right;
    self.pieceLab.nim_centerY = self.pieceTitleLab.nim_centerY;
    self.pieceLab.nim_width = self.bgView.nim_width - 10 - self.pieceTitleLab.nim_right;
    
    self.countTitleLab.text = @"货物数量：";
    [self.countTitleLab sizeToFit];
    self.countTitleLab.nim_left = 10;
    self.countTitleLab.nim_top = self.pieceTitleLab.nim_bottom + 5;
    
    self.countLab.text = self.model.goodsNum;
    [self.countLab sizeToFit];
    self.countLab.nim_left = self.countTitleLab.nim_right;
    self.countLab.nim_centerY = self.countTitleLab.nim_centerY;
    self.countLab.nim_width = self.bgView.nim_width - 10 - self.countTitleLab.nim_right;
    
    self.faTimeTitleLab.text = @"发货时间：";
    [self.faTimeTitleLab sizeToFit];
    self.faTimeTitleLab.nim_left = 10;
    self.faTimeTitleLab.nim_top = self.countTitleLab.nim_bottom + 5;
    
    self.faTimeLab.text = self.model.send_time;
    [self.faTimeLab sizeToFit];
    self.faTimeLab.nim_left = self.faTimeTitleLab.nim_right;
    self.faTimeLab.nim_centerY = self.faTimeTitleLab.nim_centerY;
    self.faTimeLab.nim_width = self.bgView.nim_width - 10 - self.faTimeTitleLab.nim_right;
    
    self.daoTimeTitleLab.text = @"要求到达时间：";
    [self.daoTimeTitleLab sizeToFit];
    self.daoTimeTitleLab.nim_left = 10;
    self.daoTimeTitleLab.nim_top = self.faTimeTitleLab.nim_bottom + 5;
    
    self.daoTimeLab.text = self.model.arrivalTime;
    [self.daoTimeLab sizeToFit];
    self.daoTimeLab.nim_left = self.daoTimeTitleLab.nim_right;
    self.daoTimeLab.nim_centerY = self.daoTimeTitleLab.nim_centerY;
    self.daoTimeLab.nim_width = self.bgView.nim_width - 10 - self.daoTimeTitleLab.nim_right;
    
    self.bgView.nim_height = self.daoTimeTitleLab.nim_bottom + 15;
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
